export const getDistance = (lat1: number, lng1: number, lat2: number, lng2: number) => {
    console.log(lat1, lng1, lat2, lng2)
    lat1 = lat1 || 0
    lng1 = lng1 || 0
    lat2 = lat2 || 0
    lng2 = lng2 || 0
    var rad1 = lat1 * Math.PI / 180.0
    var rad2 = lat2 * Math.PI / 180.0
    var a = rad1 - rad2
    var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0
    var r = 6378137
    var distance = r * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad1) * Math.cos(rad2) * Math.pow(Math.sin(b / 2), 2)))
    return (distance/1000).toFixed(2)
}

export const ataURLtoBlob = (dataurl: any) => {
    let arr = dataurl.split(',')
    let mime = arr[0].match(/:(.*?);/)[1]
    let bstr = atob(arr[1])
    let n = bstr.length
    let u8arr = new Uint8Array(n)
    while (n--) {
        u8arr[n] = bstr.charCodeAt(n)
    }
    return new Blob([u8arr], { type: mime })
}